package client.comm.baoding.fragment

import android.view.View
import client.comm.commlib.base.BaseFragment
import client.comm.commlib.toast.toast
import client.comm.commlib.widget.EmptyLayout
import client.comm.baoding.R
import client.comm.baoding.databinding.FragmentSetxxfourBinding
import client.comm.baoding.databinding.FragmentSetxxthreeBinding
import client.comm.baoding.ui.vm.SetskxxViewModel

class SetxxFourFragment : BaseFragment<FragmentSetxxfourBinding, SetskxxViewModel>() {
    override fun getViewId(): Int {
        return R.layout.fragment_setxxfour
    }

    override fun initViewModel(): SetskxxViewModel = createViewModel()

    override fun initWidget() {
        binding.event = this
        binding.vm = viewModel

        viewModel.callFour.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    toast("成功")
                    requireActivity().finish()
                } else {
//                    toast(it.message)
                }
            }
        })

        binding.emptyLayout.setOnClickListener {
            viewModel.callFour()
        }

        viewModel.dataFour.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    it.data?.pay_list?.let {
                        if (it.size > 0) {
                            viewModel.realNameFour.value = it.get(0).real_name
                            viewModel.payCardFour.value = it.get(0).pay_card
                            viewModel.phoneFour.value = it[0].bank_name
                        }
                    }
                    binding.emptyLayout.visibility = View.GONE
                } else {
//                    toast(it.message)
                    binding.emptyLayout.errorType = EmptyLayout.NETWORK_ERROR
                }
            }
        })
        viewModel.callFour()
    }

}